package com.yunyao.dao.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunyao.common.constant.enums.DataDeletedStatus;
import com.yunyao.dao.model.SysRole;
import com.yunyao.dao.mapper.SysRoleMapper;
import com.yunyao.dao.service.system.ISysRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.compress.utils.Lists;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author xingjishuai
 * @since 2024-07-02
 */
@Slf4j
@Service(value = "yunyaoSysRoleService")
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    @Override
    public List<SysRole> getRoleListByIds(List<String> roleIdList) {
        if (CollectionUtils.isEmpty(roleIdList)) {
            return Lists.newArrayList();
        }
        LambdaQueryWrapper<SysRole> wrapper = new LambdaQueryWrapper<SysRole>()
                .in(SysRole::getId, roleIdList)
                .eq(SysRole::getIsDeleted, DataDeletedStatus.NO.getType());
        return baseMapper.selectList(wrapper);
    }

    @Override
    public Map<String, SysRole> getRoleMapByIds(List<String> roleIdList) {
        List<SysRole> sysRoleList = getRoleListByIds(roleIdList);
        if (CollectionUtils.isEmpty(sysRoleList)) {
            return new HashMap<>();
        }
        return sysRoleList.stream().collect(Collectors.toMap(SysRole::getId, Function.identity(), (k1, k2) -> k1));
    }
}
